<template>
  <div>
    <div style="margin:50px 15% 0 15%">
      <h1 style="font-size:80px;margin-bottom:3%" v-if="data!=null">
        {{t.commentMsg}}
      </h1>
      <b-field label="评论写在这里">
        <b-input maxlength="200" type="textarea" v-model="message"></b-input>
      </b-field>
      <b-button type="is-success" outlined @click="onPost()">发表评论</b-button>
    </div>

    <b-table
        :data="data"
        :columns="columns"
        style="margin:50px 10% 0 10%"
    ></b-table>
  </div>
</template>

<script>
export default {
  name: "post",
  data() {
    return {
      t:"",
      title:"",
      id:"",
      message: "",
      data: [],
      columns: [
        {
          field: "answerMsg",
          label: "评论",
        },
        {
          field:"user.userName",
          label:"用户",
        },
      ],
    };
  },
  methods: {
    async onPost(){
      let res=await this.$http.post('api/2backcode/answer/add?answerMsg='+this.message+'&id='+this.id+'&commentId='+this.title)
      console.log(res.data)
      this.$router.go(0)
    },
    async init() {
      this.id=await localStorage.getItem("email")
      this.title = this.$route.query.title;
      // console.log(this.$route.query.title);
      let res = await this.$http.get("api/2backcode/answer/find", {
        params: {
          commentId: this.title,
        },
      });
      console.log(res.data);
      this.data = res.data;
      let res2=await this.$http.get("api/2backcode/comment/findone",{
        params:{
          commentId:this.title
        }
      })
      this.t=res2.data
    },
  },
  mounted() {
    this.init();
  },
};
</script>

<style></style>
